package com.example.evanproject.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.evanproject.domain.User;
import com.example.evanproject.service.UserService;
import com.example.evanproject.mapper.UserMapper;
import com.example.evanproject.util.EntityMapUtils;
import com.example.evanproject.util.ReturnsData;
import com.example.evanproject.util.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
* @author hanxiaoqi
* @description 针对表【user】的数据库操作Service实现
* @createDate 2024-03-09 21:52:13
*/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
    implements UserService{


    @Autowired

    private UserMapper userMapper;

    public User selectinfo(Integer id){

        return userMapper.selectinfo(id);
    }

    public ReturnsData login(String name, String pass) {
        String token=null;
        ReturnsData returnsData =new ReturnsData();
        User user=userMapper.login(name,pass);
        if(user!=null){
            token= TokenUtils.createToken(user.getUserid().toString(),pass);
            Map<String,Object> retrunlist= EntityMapUtils.entityToMap(userMapper.login(name,pass));
            retrunlist.put("token",token);
            System.out.println(retrunlist);
            returnsData.setCode(200);
            returnsData.setData(retrunlist);
            return returnsData;
        }
        else {
            returnsData.setCode(400);
            return returnsData;
        }


    }

    public List<User> selectlist() {
        return userMapper.selectlist();
    }
    //  修改信息
    public Integer updatelist(Integer id, String name, String pass) {

        return userMapper.updatelist(id,name,pass);
    }
}




